﻿

using ZingBlog.Web.Areas.Admin.Controllers;
using System;
using Microsoft.AspNetCore.Mvc;
using ZingBlog.IService;
using ZingBlog.Dto;
using ZingBlog.Domain.Entities;

namespace ZingBlog.Web.Areas.Blog.Controllers
{
    [Area("Blog")]
    public class ArticleTypeController : BaseController
    {
        public IArticleTypeService articleTypeService { get; set; }
        public override ActionResult Index(int? Id)
        {
            base.Index(Id);
            return View();
        }
        [HttpGet]
        public JsonResult List(ArticleTypeEntity filter, PageInfo pageInfo)
        {
            var result = articleTypeService.GetListByFilter(filter, pageInfo);
            return Json(result);
        }
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(ArticleTypeEntity model)
        {
            model.CreateOn = DateTime.Now;
            var result = articleTypeService.CreateEntity(model) ? SuccessTip() : ErrorTip();
            return Json(result);
        }
        public ActionResult Detail(int Id)
        {
            var model = articleTypeService.ReadEntity(Id);
            return View(model);
        }
        public ActionResult Edit(int Id)
        {
            var model = articleTypeService.ReadEntity(Id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(ArticleTypeEntity model)
        {
            var result = articleTypeService.UpdateEntity(model) ? SuccessTip() : ErrorTip();
            return Json(result);
        }
        [HttpPost]
        public ActionResult Delete(int Id)
        {
            //一般类别就是：原创，转载，翻译，所以不做联动删除文章。
            var result = articleTypeService.DeleteEntity(Id) ? SuccessTip() : ErrorTip();
            return Json(result);
        }
    }
}